<?php
require_once 'function.php';
require_once 'lang/french.php';
require_once 'header.php';
if(isset($_POST['host']))	$basesql['serveur'] = $_POST['host'];
else    $basesql['serveur'] = 'localhost';
if(isset($_POST['dbuser']))	$basesql['user']  = $_POST['dbuser'];
else    $basesql['user'] = 'root';
if(isset($_POST['dbbasse']))	$basesql['password'] = $_POST['dbpass'];
else $basesql['password'] = '';
if(isset($_POST['dbbasse']))	$basesql['base'] = $_POST['dbbasse'];
else $basesql['base'] = '';

if(isset($_GET['test']))
{
    require_once '../kernel/db/class_'. $_POST['typebase'] .'.php';
    $db = new db_sql();
    $connexion = $db->sql_connect($basesql);
    if($connexion == 1)
    {
        // Creation de la base
        switch($_POST['typebase'])
        {
            case 'mysql':
                require_once 'sql/construct_mysql.php';
                write_config_file($basesql, $_POST);
                redirect('page_compte_admin.php');
            break;
            
            case 'postgre':
            break;
        }
        
    }
}

echo'
<h3>'. $lang['CONFIGURATION_DB'] .'</h3>
<br />
<br />
<form method="post" action="page_config_database.php?test">
<fieldset>
    <legend class="legend_install">'. $lang['SYSTEME_DE_DB'] .'</legend>
    <br />
    <label>' . $lang['SYSTEME_DE_DB'] .'</label> : 
    <select name="typebase">
        <option value="mysql"'; if(isset($_POST['typebase']) && $_POST['typebase'] == "mysql") echo 'selected="selected"'; echo'>MySql</option>
    </select>
    <br />
    <br />
</fieldset>
<br />
<br />
<br />
<fieldset>
	<legend>'. $lang['CONFIGURATION_DB'] .'</legend>
	<br />
	<table>
	<tr>
		<td>'. $lang['SERVER_DB'] .' :</td>
		<td><input type="text" name="host" size="30" value="'. $basesql['serveur'] .'"/></td>
	</tr>
	<tr>
		<td>'. $lang['UTILISATEUR_DB'] .' :</td>
		<td><input type="text" name="dbuser" size="30" value="'. $basesql['user'] .'"/></td>
	</tr>
	<tr>
		<td>'. $lang['MOT_DE_PASSE'] .' :</td>
		<td><input type="text" name="dbpass" size="30" /></td>
	</tr>
	<tr>
		<td>'. $lang['BASE_DE_DONNEE'] .' :</td>
		<td><input type="text" name="dbbasse" size="30" value="'. $basesql['base'] .'"/></td>
	</tr>
	</table>
</fieldset>';
if($connexion != 1 && isset($_GET['test']))
	{
		echo'
		<br />
		<br />
		<fieldset>
			<legend class="legend_install">'. $lang['RESULTAT_TEST_DB'] .'</legend>
			<br />
			<div style="margin: auto; width: 75%;">
				<div class="bad100">
					<div style="float: left;">
						<img src="images/alert.gif" border="0" />
					</div>
					<div>'. $connexion .'</div>
					<div style="clear: both;"></div>
			</div>
		</fieldset>';
	}
echo'
<br />
<br />
<div style="text-align: center;"><input type="submit" style="background:url(\'images/bleu_suivant.png\'); height:48px; width:48px; border: none; cursor: pointer; " value=""/></div>
</form>';
require_once 'footer.php';
?>